


use "../2_Data/temp/data_selected_region.dta", clear

levelsof codice_regione, local(prov)

foreach province in `prov' {
    
	gen trend_prov`province'= (codice_regione==`province')*trend*(post==0)
}


local trends trend_prov1 trend_prov3 trend_prov5 trend_prov8 trend_prov10 trend_prov11 trend_prov12 trend_prov14 trend_prov16 trend_prov18 trend_prov19


gen aux =.

cap drop M1 M2 M3 M4
local var daily_increase

local figure "_`var'_trends"
matrix B = [.]
		matrix CIL = [.]
		matrix CIU = [.]
		matrix ITER = [.]

		
eststo clear		
eststo: reg2hdfespatial `var' pla6 pla5 pla4 pla3 pla2 pla1 cam cam1 cam2 cam3 cam4 cam5 cam6 cam7 cam8 `trends', lat(x_region) lon(y_region) timevar(time_fe_region) panelvar(region_code) distcutoff(1300) lagcutoff(110)

estout est1, cells(b se)

matrix help = r(coefs)

matrix list help

forvalues i = 1/5 {
matrix B = [B,help[`i',1]]
matrix CIL = [CIL, help[`i',1]-help[`i',2]* 1.96]
matrix CIU = [CIU, help[`i',1]+help[`i',2]* 1.96]
matrix ITER = [ITER, `i']
}

matrix B = [B,0]
matrix CIL = [CIL,.]
matrix CIU = [CIU,.]
matrix ITER = [ITER,6]

forvalues i = 6/14 {
local j = `i'+1
matrix B = [B,help[`i',1]]
matrix CIL = [CIL, help[`i',1]-help[`i',2]* 1.96]
matrix CIU = [CIU, help[`i',1]+help[`i',2]* 1.96]
matrix ITER = [ITER, `j']
}

		matrix M = [B \ CIL \ CIU \ ITER]'
		svmat M
		replace M1 = . if M2 == 0 & M3 == 0
		replace M2 = . if M1 == .
		replace M3 = . if M1 == .
		
tw (rcap M2 M3 M4, lcolor(gs11) lwidth() ) (scatter M1 M4, color(gs6) msymbol(circle)), yline(0, lcolor(red))  xtitle("Weeks from campaign start", size(large)) /// 
ylabel(-.25 "-0.25" 0 "0" .25 "0.25", labsize(large) angle(0)) xline(6, lpattern("--") lcolor(black))  scheme(s1mono) graphregion(fcolor(white) color(white))  ///
xlabel(1 "-6" 2 "-5" 3 "-4" 4 "-3" 5 "-2" 6 "-1" 7 "0" 8 "+1" 9 "+2" 10 "+3" 11 "+4" 12 "+5" 13 "+6" 14 "+7" 15 "+8", labsize(large) angle(45)) legend(off)


cap drop M1 M2 M3 M4
local var tamponi_day

local figure "_`var'_trends"
matrix B = [.]
		matrix CIL = [.]
		matrix CIU = [.]
		matrix ITER = [.]

		
eststo clear		
eststo: reg2hdfespatial `var' pla6 pla5 pla4 pla3 pla2 pla1 cam cam1 cam2 cam3 cam4 cam5 cam6 cam7 cam8 `trends', lat(x_region) lon(y_region) timevar(time_fe_region) panelvar(region_code) distcutoff(1300) lagcutoff(110)

estout est1, cells(b se)

matrix help = r(coefs)

matrix list help

forvalues i = 1/5 {
matrix B = [B,help[`i',1]]
matrix CIL = [CIL, help[`i',1]-help[`i',2]* 1.96]
matrix CIU = [CIU, help[`i',1]+help[`i',2]* 1.96]
matrix ITER = [ITER, `i']
}

matrix B = [B,0]
matrix CIL = [CIL,.]
matrix CIU = [CIU,.]
matrix ITER = [ITER,6]

forvalues i = 6/14 {
local j = `i'+1
matrix B = [B,help[`i',1]]
matrix CIL = [CIL, help[`i',1]-help[`i',2]* 1.96]
matrix CIU = [CIU, help[`i',1]+help[`i',2]* 1.96]
matrix ITER = [ITER, `j']
}

		matrix M = [B \ CIL \ CIU \ ITER]'
		svmat M
		replace M1 = . if M2 == 0 & M3 == 0
		replace M2 = . if M1 == .
		replace M3 = . if M1 == .
		
tw (rcap M2 M3 M4, lcolor(gs11) lwidth() ) (scatter M1 M4, color(gs6) msymbol(circle)), yline(0, lcolor(red))  xtitle("Weeks from campaign start", size(large)) /// 
ylabel(-.25 "-0.25" 0 "0" .25 "0.25", labsize(large) angle(0)) xline(6, lpattern("--") lcolor(black))  scheme(s1mono) graphregion(fcolor(white) color(white))  ///
xlabel(1 "-6" 2 "-5" 3 "-4" 4 "-3" 5 "-2" 6 "-1" 7 "0" 8 "+1" 9 "+2" 10 "+3" 11 "+4" 12 "+5" 13 "+6" 14 "+7" 15 "+8", labsize(large) angle(45)) legend(off)



cap drop M1 M2 M3 M4
local var ratio2

local figure "_`var'_trends"
matrix B = [.]
		matrix CIL = [.]
		matrix CIU = [.]
		matrix ITER = [.]

		
eststo clear		
eststo: reg2hdfespatial `var' pla6 pla5 pla4 pla3 pla2 pla1 cam cam1 cam2 cam3 cam4 cam5 cam6 cam7 cam8 `trends', lat(x_region) lon(y_region) timevar(time_fe_region) panelvar(region_code) distcutoff(1300) lagcutoff(110)

estout est1, cells(b se)

matrix help = r(coefs)

matrix list help

forvalues i = 1/5 {
matrix B = [B,help[`i',1]]
matrix CIL = [CIL, help[`i',1]-help[`i',2]* 1.96]
matrix CIU = [CIU, help[`i',1]+help[`i',2]* 1.96]
matrix ITER = [ITER, `i']
}

matrix B = [B,0]
matrix CIL = [CIL,.]
matrix CIU = [CIU,.]
matrix ITER = [ITER,6]

forvalues i = 6/14 {
local j = `i'+1
matrix B = [B,help[`i',1]]
matrix CIL = [CIL, help[`i',1]-help[`i',2]* 1.96]
matrix CIU = [CIU, help[`i',1]+help[`i',2]* 1.96]
matrix ITER = [ITER, `j']
}

		matrix M = [B \ CIL \ CIU \ ITER]'
		svmat M
		replace M1 = . if M2 == 0 & M3 == 0
		replace M2 = . if M1 == .
		replace M3 = . if M1 == .
		
tw (rcap M2 M3 M4, lcolor(gs11) lwidth() ) (scatter M1 M4, color(gs6) msymbol(circle)), yline(0, lcolor(red))  xtitle("Weeks from campaign start", size(large)) /// 
ylabel(-0.4 "-0.40" 0 "0" 0.4 "0.40", labsize(large) angle(0)) xline(6, lpattern("--") lcolor(black))  scheme(s1mono) graphregion(fcolor(white) color(white))  ///
xlabel(1 "-6" 2 "-5" 3 "-4" 4 "-3" 5 "-2" 6 "-1" 7 "0" 8 "+1" 9 "+2" 10 "+3" 11 "+4" 12 "+5" 13 "+6" 14 "+7" 15 "+8", labsize(large) angle(45)) legend(off)



cap drop M1 M2 M3 M4
local var totale_osp

local figure "_`var'_trends"
matrix B = [.]
		matrix CIL = [.]
		matrix CIU = [.]
		matrix ITER = [.]

		
eststo clear		
eststo: reg2hdfespatial `var' pla6 pla5 pla4 pla3 pla2 pla1 cam cam1 cam2 cam3 cam4 cam5 cam6 cam7 cam8 `trends', lat(x_region) lon(y_region) timevar(time_fe_region) panelvar(region_code) distcutoff(1300) lagcutoff(110)

estout est1, cells(b se)

matrix help = r(coefs)

matrix list help

forvalues i = 1/5 {
matrix B = [B,help[`i',1]]
matrix CIL = [CIL, help[`i',1]-help[`i',2]* 1.96]
matrix CIU = [CIU, help[`i',1]+help[`i',2]* 1.96]
matrix ITER = [ITER, `i']
}

matrix B = [B,0]
matrix CIL = [CIL,.]
matrix CIU = [CIU,.]
matrix ITER = [ITER,6]

forvalues i = 6/14 {
local j = `i'+1
matrix B = [B,help[`i',1]]
matrix CIL = [CIL, help[`i',1]-help[`i',2]* 1.96]
matrix CIU = [CIU, help[`i',1]+help[`i',2]* 1.96]
matrix ITER = [ITER, `j']
}

		matrix M = [B \ CIL \ CIU \ ITER]'
		svmat M
		replace M1 = . if M2 == 0 & M3 == 0
		replace M2 = . if M1 == .
		replace M3 = . if M1 == .
		
tw (rcap M2 M3 M4, lcolor(gs11) lwidth() ) (scatter M1 M4, color(gs6) msymbol(circle)), yline(0, lcolor(red))  xtitle("Weeks from campaign start", size(large)) /// 
ylabel(-.60 "-0.60" 0 "0" .60 "0.60", labsize(large) angle(0)) xline(6, lpattern("--") lcolor(black))  scheme(s1mono) graphregion(fcolor(white) color(white))  ///
xlabel(1 "-6" 2 "-5" 3 "-4" 4 "-3" 5 "-2" 6 "-1" 7 "0" 8 "+1" 9 "+2" 10 "+3" 11 "+4" 12 "+5" 13 "+6" 14 "+7" 15 "+8", labsize(large) angle(45)) legend(off)


cap drop M1 M2 M3 M4
local var terapia

local figure "_`var'_trends"
matrix B = [.]
		matrix CIL = [.]
		matrix CIU = [.]
		matrix ITER = [.]

		
eststo clear		
eststo: reg2hdfespatial `var' pla6 pla5 pla4 pla3 pla2 pla1 cam cam1 cam2 cam3 cam4 cam5 cam6 cam7 cam8 `trends', lat(x_region) lon(y_region) timevar(time_fe_region) panelvar(region_code) distcutoff(1300) lagcutoff(110)

estout est1, cells(b se)

matrix help = r(coefs)

matrix list help

forvalues i = 1/5 {
matrix B = [B,help[`i',1]]
matrix CIL = [CIL, help[`i',1]-help[`i',2]* 1.96]
matrix CIU = [CIU, help[`i',1]+help[`i',2]* 1.96]
matrix ITER = [ITER, `i']
}

matrix B = [B,0]
matrix CIL = [CIL,.]
matrix CIU = [CIU,.]
matrix ITER = [ITER,6]

forvalues i = 6/14 {
local j = `i'+1
matrix B = [B,help[`i',1]]
matrix CIL = [CIL, help[`i',1]-help[`i',2]* 1.96]
matrix CIU = [CIU, help[`i',1]+help[`i',2]* 1.96]
matrix ITER = [ITER, `j']
}

		matrix M = [B \ CIL \ CIU \ ITER]'
		svmat M
		replace M1 = . if M2 == 0 & M3 == 0
		replace M2 = . if M1 == .
		replace M3 = . if M1 == .
		
tw (rcap M2 M3 M4, lcolor(gs11) lwidth() ) (scatter M1 M4, color(gs6) msymbol(circle)), yline(0, lcolor(red))  xtitle("Weeks from campaign start", size(large)) /// 
ylabel(-.25 "-0.25" 0 "0" .25 "0.25", labsize(large) angle(0)) xline(6, lpattern("--") lcolor(black))  scheme(s1mono) graphregion(fcolor(white) color(white))  ///
xlabel(1 "-6" 2 "-5" 3 "-4" 4 "-3" 5 "-2" 6 "-1" 7 "0" 8 "+1" 9 "+2" 10 "+3" 11 "+4" 12 "+5" 13 "+6" 14 "+7" 15 "+8", labsize(large) angle(45)) legend(off)


cap drop M1 M2 M3 M4
local var deceduti_day


local figure "_`var'_trends"
matrix B = [.]
		matrix CIL = [.]
		matrix CIU = [.]
		matrix ITER = [.]

		
eststo clear		
eststo: reg2hdfespatial `var' pla6 pla5 pla4 pla3 pla2 pla1 cam cam1 cam2 cam3 cam4 cam5 cam6 cam7 cam8  `trends', lat(x_region) lon(y_region) timevar(time_fe_region) panelvar(region_code) distcutoff(1300) lagcutoff(110)

estout est1, cells(b se)

matrix help = r(coefs)

matrix list help

forvalues i = 1/5 {
matrix B = [B,help[`i',1]]
matrix CIL = [CIL, help[`i',1]-help[`i',2]* 1.96]
matrix CIU = [CIU, help[`i',1]+help[`i',2]* 1.96]
matrix ITER = [ITER, `i']
}

matrix B = [B,0]
matrix CIL = [CIL,.]
matrix CIU = [CIU,.]
matrix ITER = [ITER,6]

forvalues i = 6/14 {
local j = `i'+1
matrix B = [B,help[`i',1]]
matrix CIL = [CIL, help[`i',1]-help[`i',2]* 1.96]
matrix CIU = [CIU, help[`i',1]+help[`i',2]* 1.96]
matrix ITER = [ITER, `j']
}

		matrix M = [B \ CIL \ CIU \ ITER]'
		svmat M
		replace M1 = . if M2 == 0 & M3 == 0
		replace M2 = . if M1 == .
		replace M3 = . if M1 == .
		
tw (rcap M2 M3 M4, lcolor(gs11) lwidth() ) (scatter M1 M4, color(gs6) msymbol(circle)), yline(0, lcolor(red))  xtitle("Weeks from campaign start", size(large)) /// 
ylabel(-.02 "-0.02" 0 "0" .02 "0.02", labsize(large) angle(0)) xline(6, lpattern("--") lcolor(black))  scheme(s1mono) graphregion(fcolor(white) color(white))  ///
xlabel(1 "-6" 2 "-5" 3 "-4" 4 "-3" 5 "-2" 6 "-1" 7 "0" 8 "+1" 9 "+2" 10 "+3" 11 "+4" 12 "+5" 13 "+6" 14 "+7" 15 "+8", labsize(large) angle(45)) legend(off)


